package com.wendal.java.happydog.action;

import java.util.HashMap;
import java.util.Map;

import com.wendal.java.happydog.HappyDogContent;

public class FeedAction extends AbstractAction {

	public static final String FEED_WATER = "1"; 
	public static final String FEED_FOOD = "2";
	
	private static final String ActionURL = "http://dog.kaixin.com/pet-profile.do";
	
	protected HappyDogContent content;

	@Override
	public void execute(HappyDogContent content, Object... args) {
		if(args == null || args.length != 2) return;
		if(args[0] == null || args[1] == null) return;
		String actionType = String.valueOf(args[0]);
		String petId = String.valueOf(args[1]);
		this.content = content;
		if(FEED_WATER.equals(actionType)|| FEED_FOOD.equals(actionType)){
			try {
			//进入页面
			content.getClientVM().accessURL("http://apps.kaixin.com/kxdog_app/pet-profile.do");
			// method=doing&active%5Fid=1&pid=6722831&actor%5Fid=712552485&code=6b6ddb0ff1a7a7ebdf20d9c76998834c
			Map<String, String> keyValue = new HashMap<String, String>();
			keyValue.put("pid", petId);
			keyValue.put("active_id", "1");
			keyValue.put("method", "doing");
			keyValue.put("actor_id", content.getMyId());
			keyValue.put("code", "6b6ddb0ff1a7a7ebdf20d9c76998834c");
			
			String result = content.getClientVM().accessURL_Post(ActionURL, keyValue, "UTF-8");
			log.info(result);
			} catch (Throwable e) {
				e.printStackTrace();
			}
		}
	}
	
	protected void feedWater(String petId) {
		try {
			//进入页面
			content.getClientVM().accessURL("http://apps.kaixin.com/kxdog_app/pet-profile.do");
			// method=doing&active%5Fid=1&pid=6722831&actor%5Fid=712552485&code=6b6ddb0ff1a7a7ebdf20d9c76998834c
			Map<String, String> keyValue = new HashMap<String, String>();
			keyValue.put("pid", petId);
			keyValue.put("active_id", "1");
			keyValue.put("method", "doing");
			keyValue.put("actor_id", content.getMyId());
			keyValue.put("code", "?");
			
			String result = content.getClientVM().accessURL_Post(ActionURL, keyValue, "UTF-8");
			log.info(result);
		} catch (Throwable e) {
			e.printStackTrace();
		}
	}

	protected void feedFood(String petId) {
		
	}
}
